package com.pillar.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.pillar.game.NodeStatus;
import com.pillar.request.BasePackage;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;

/**
 * @author pillar
 * @desc
 * @email: 347637454@qq.com
 * @createDate 2021-01-08 23:03
 */
@Slf4j
public abstract class AbstractCheckLoginHandler implements IHandler{

    @Override
    public boolean consume(Channel channel, BasePackage basePackage) throws JsonProcessingException {
        if (null == NodeStatus.findChannel(basePackage.getUuid())){
            log.error("请重新登录");
            channel.close();
            return false;
        }
        return false;
    }
    void writeText(Channel channel, String text){
        if (channel.isActive()){
            channel.writeAndFlush(new TextWebSocketFrame(text));
        }
    }
}
